{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[22, 44, 66, 88, 110]\n"
     ]
    }
   ],
   "source": [
    "# map(function, iterable, ...)\n",
    "# map() applies a function to all the items in an input_list return iter\n",
    "def add_five(x,y):\n",
    "    return x + y\n",
    "\n",
    "nums = [11, 22, 33, 44, 55]\n",
    "result = list(map(add_five, nums,nums))\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# map()函数返回的是一个迭代器对象，而不是立即执行函数。当你使用map()函数时，它会创建一个迭代器对象，但不会立即执行其中的函数。\n",
    "# 只有当你对迭代器进行迭代或将其转换为列表等可迭代对象时，才会逐个执行函数。\n",
    "list(map(lambda x: print(x) ,[1,2,3]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# filter demo\n",
    "# filter(function, iterable)\n",
    "\n",
    "def check_even(num):\n",
    "    return num % 2 == 0\n",
    "\n",
    "nums = [11, 22, 33, 44, 55]\n",
    "\n",
    "result = list(filter(check_even, nums))\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# reduce \n",
    "# reduce(function, iterable)\n",
    "from functools import reduce\n",
    "\n",
    "def prod(L):\n",
    "    return reduce(lambda x, y: x * y, L)\n",
    "\n",
    "prod((1,2,3,4,5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "min\n",
    "max\n",
    "sum\n",
    "len\n",
    "any demo\n",
    "all demo\n",
    "'''\n",
    "\n",
    "# any demo\n",
    "# any() returns True if any element of an iterable is true. If not, any() returns False.\n",
    "# If the iterable is empty, any() will return False.\n",
    "print(any([1, 2, 3, 4, 5]))\n",
    "\n",
    "# all demo\n",
    "# all() returns True if all elements of the iterable are true (or if the iterable is empty).\n",
    "print(all([1, 2, 3, 0, 5]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# iter() returns an iterator object.\n",
    "# iter(object[, sentinel])\n",
    "# object - object whose iterator has to be created\n",
    "# sentinel - (optional) used to stop the iteration\n",
    "# If the second parameter (sentinel) is specified, the iterator created is an object called a callable iterator.\n",
    "# The iterator stops when the function returns the sentinel value.\n",
    "print(iter([1, 2, 3, 4, 5]))\n",
    "\n",
    "# next(iterator[, default])\n",
    "# iterator - iterator object\n",
    "# default - (optional) value to be returned if the iterator is exhausted\n",
    "# The next() function returns the next item from the iterator.\n",
    "# If default is specified and the iterator is exhausted, it is returned instead of raising StopIteration.\n",
    "print(next(x:=iter([1, 2, 3, 4, 5])))\n",
    "print(next(x))\n",
    "print(next(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# zip(*iterables)\n",
    "# zip() returns an iterator of tuples based on the iterable object.\n",
    "# If multiple iterables are passed, the iterator stops when the shortest iterable is exhausted.\n",
    "# iterables - iterables which are to be zipped; they may be either a sequence, an iterator, or some other iterable object.\n",
    "# If no iterables are passed, zip() returns an empty iterator.\n",
    "print(x:=zip([1, 2, 3, 4, 5], [6, 7, 8, 9, 10]))\n",
    "print(next(x))\n",
    "\n",
    "# enumerate(iterable, start=0)\n",
    "# The enumerate() function takes a collection (e.g. a tuple) and returns it as an enumerate object.\n",
    "# The syntax of enumerate() is:\n",
    "# iterable - a sequence, an iterator, or objects that supports iteration\n",
    "# start (optional) - enumerate() starts counting from this number. If start is omitted, 0 is taken as start.\n",
    "print(x:=enumerate([1, 2, 3, 4, 5]))\n",
    "print(next(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# sorted(iterable, key=None, reverse=False)\n",
    "# The sorted() function returns a sorted list from the items in an iterable.\n",
    "# iterable - iterable object\n",
    "# key (optional) - function that serves as a key for the sort comparison\n",
    "# reverse (optional) - If true, the sorted list is reversed (or sorted in Descending order)\n",
    "# If no parameters are passed, the default sorting order is ascending.\n",
    "\n",
    "print(sorted([5, 2, 3, 1, 4]))\n",
    "print(sorted([(5, 2), (3, 1), (4, 9)], key=lambda x: x[1], reverse=True))\n",
    "\n",
    "\n",
    "# reversed(seq)\n",
    "# The reversed() function returns the reversed iterator of the given sequence.\n",
    "# seq - sequence (string, tuple, list) or iterator object to be reversed\n",
    "# The reversed() function doesn't sort elements in the container, it only reverses the order of elements.\n",
    "print(x := reversed([1, 2, 3, 4, 5]))\n",
    "print(next(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "itertools\n",
    "\n",
    "count\n",
    "cycle\n",
    "repeat\n",
    "accumulate\n",
    "chain\n",
    "compress\n",
    "dropwhile\n",
    "filterfalse\n",
    "groupby\n",
    "islice\n",
    "starmap\n",
    "takewhile\n",
    "tee\n",
    "zip_longest\n",
    "partial\n",
    "partialmethod\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# tee demo\n",
    "# The tee() function returns n independent iterators from a single iterable.\n",
    "# The syntax of tee() is:\n",
    "# tee(iterable, n=2)\n",
    "# iterable - iterable object\n",
    "# n (optional) - number of independent iterators to be returned (default is 2)\n",
    "# The tee() function returns a tuple of n independent iterators from a single iterable.\n",
    "\n",
    "from itertools import tee\n",
    "\n",
    "\n",
    "print(x:=tee([1, 2, 3, 4, 5],3))\n",
    "print(next(x[0]))\n",
    "print(next(x[0]))\n",
    "print(next(x[1]))\n",
    "print(next(x[2]))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# starmap demo \n",
    "# The starmap() function takes a function and a sequence of iterables as arguments.\n",
    "# It then applies the function to the elements of the sequence to produce a list of the results.\n",
    "# The syntax of starmap() is:\n",
    "# starmap(function, sequence)\n",
    "# function - function to be applied on the elements of the sequence\n",
    "# sequence - sequence of iterables\n",
    "\n",
    "from itertools import starmap\n",
    "\n",
    "def add(x, y):\n",
    "    return x + y\n",
    "\n",
    "print(list(starmap(add, [(2, 3), (4, 5), (6, 7)])))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# groupby demo\n",
    "# The groupby() function returns an iterator that produces consecutive keys and groups from the iterable.\n",
    "# The key is a function computing a key value for each element.\n",
    "# If not specified or is None, key defaults to an identity function and returns the element unchanged.\n",
    "# Generally, the iterable needs to already be sorted on the same key function.\n",
    "# The returned group is itself an iterator that shares the underlying iterable with groupby().\n",
    "# Because the source is shared, when the groupby() object is advanced, the previous group is no longer visible.\n",
    "# So, if that data is needed later, it should be stored as a list.\n",
    "# The operation of groupby() is similar to the uniq filter in Unix.\n",
    "# It generates a break or new group every time the value of the key function changes \n",
    "# (which is why it is usually necessary to have sorted the data using the same key function).\n",
    "# Since the source is shared, when the groupby() object is advanced, the previous group is no longer visible.\n",
    "# So, if that data is needed later, it should be stored as a list.\n",
    "# When the iterable is exhausted, the groupby() object raises a StopIteration exception.\n",
    "# groupby() should only be used if the data is too large to fit in memory in a single sorted list.\n",
    "# If these conditions don't apply, it's simpler and faster to sort the data with sort() and\n",
    "# iterate over it in sorted chunks with itertools.groupby().\n",
    "# The syntax of groupby() is:\n",
    "# groupby(iterable, key=None)\n",
    "# iterable - iterable object\n",
    "# key (optional) - function that serves as a key for the sort comparison\n",
    "\n",
    "from itertools import groupby\n",
    "\n",
    "print(x:=groupby([1, 2, 3, 4, 5]))\n",
    "print(next(x))\n",
    "print(next(x))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# count demo\n",
    "# The count() function returns an iterator that produces consecutive integers, \n",
    "# starting from the value passed as an argument.\n",
    "# The syntax of count() is:\n",
    "# count(start, step)\n",
    "# start (optional) - integer starting from which the sequence of integers is to be returned\n",
    "# step (optional) - integer value which determines the increment between each integer in the sequence\n",
    "# If start is not specified, 0 is taken as start. If step is not specified, 1 is taken as step.\n",
    "# The count() function is an infinite iterator,\n",
    "# so it must be combined with another function that terminates the iteration,\n",
    "# otherwise it goes into an infinite loop.\n",
    "\n",
    "\n",
    "from itertools import count\n",
    "\n",
    "for i in count(10):\n",
    "    print(i)\n",
    "    if i == 15:\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# cycle demo\n",
    "# The cycle() function returns an iterator that produces all the values of the iterable passed as an argument repeatedly.\n",
    "# The syntax of cycle() is:\n",
    "# cycle(iterable)\n",
    "# iterable - iterable object\n",
    "# The cycle() function is an infinite iterator,\n",
    "# so it must be combined with another function that terminates the iteration,\n",
    "# otherwise it goes into an infinite loop.\n",
    "\n",
    "from itertools import cycle\n",
    "\n",
    "for i in cycle([1, 2, 3]):\n",
    "    print(i)\n",
    "    if i == 3:\n",
    "        break\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# repeat demo\n",
    "# The repeat() function returns an iterator that produces the same value over and over again.\n",
    "# The syntax of repeat() is:\n",
    "# repeat(object[, times])\n",
    "# object - object whose value is to be repeated\n",
    "# times (optional) - number of times the object is to be repeated\n",
    "# If times is not specified, the object is repeated indefinitely.\n",
    "# The repeat() function is an infinite iterator,\n",
    "# so it must be combined with another function that terminates the iteration,\n",
    "# otherwise it goes into an infinite loop.\n",
    "\n",
    "from itertools import repeat\n",
    "\n",
    "for i in repeat(25, 4):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# accumulate demo\n",
    "# The accumulate() function returns an iterator that returns accumulated sums,\n",
    "# or accumulated results of other binary functions (specified via the optional func argument).\n",
    "# The syntax of accumulate() is:\n",
    "# accumulate(iterable[, func])\n",
    "# iterable - iterable object\n",
    "# func (optional) - function that specifies how to accumulate the elements\n",
    "# If func is not specified, addition is assumed.\n",
    "# The accumulate() function is an infinite iterator,\n",
    "# so it must be combined with another function that terminates the iteration,\n",
    "# otherwise it goes into an infinite loop.\n",
    "\n",
    "from itertools import accumulate\n",
    "\n",
    "print(x:=accumulate([1, 2, 3, 4, 5],lambda x, y: x * y))\n",
    "print(next(x))\n",
    "print(next(x))\n",
    "print(next(x))\n",
    "print(next(x))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# chain demo\n",
    "# The chain() function returns an iterator that produces elements from the first iterable until it is exhausted,\n",
    "# then proceeds to the next iterable, until all of the iterables are exhausted.\n",
    "# The syntax of chain() is:\n",
    "# chain(*iterables)\n",
    "# iterables - iterables to be chained together\n",
    "# The chain() function is an infinite iterator,\n",
    "# so it must be combined with another function that terminates the iteration,\n",
    "# otherwise it goes into an infinite loop.\n",
    "\n",
    "from itertools import chain\n",
    "\n",
    "for i in chain([1, 2, 3], [4, 5, 6]):\n",
    "    print(i)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# compress demo\n",
    "# The compress() function returns an iterator that filters elements \n",
    "# from data returning only those that have a corresponding element in selectors that evaluates to True.\n",
    "# The syntax of compress() is:\n",
    "# compress(data, selectors)\n",
    "# data - iterable object\n",
    "# selectors - iterable object\n",
    "# The compress() function is an infinite iterator,\n",
    "# so it must be combined with another function that terminates the iteration,\n",
    "# otherwise it goes into an infinite loop.\n",
    "\n",
    "from itertools import compress\n",
    "\n",
    "print(x:=compress([1, 2, 3, 4, 5], [True, False, True, False, True]))\n",
    "print(next(x))\n",
    "print(next(x))\n",
    "print(next(x))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# dropwhile demo\n",
    "# The dropwhile() function returns an iterator that drops elements from the iterable as long as the predicate is true;\n",
    "# afterwards, returns every element.\n",
    "# The syntax of dropwhile() is:\n",
    "# dropwhile(predicate, iterable)\n",
    "# predicate - function that tests if elements of an iterable should be dropped or not\n",
    "# iterable - iterable object\n",
    "# The dropwhile() function is an infinite iterator,\n",
    "# so it must be combined with another function that terminates the iteration,\n",
    "# otherwise it goes into an infinite loop.\n",
    "\n",
    "from itertools import dropwhile\n",
    "\n",
    "print(x := dropwhile(lambda x: x < 5, [1, 4, 6, 4, 1, 2]))\n",
    "print(next(x))\n",
    "print(next(x))\n",
    "print(next(x))\n",
    "while x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# pairwise demo\n",
    "# The pairwise() function returns an iterator that returns consecutive pairs of elements from the iterable.\n",
    "# The syntax of pairwise() is:\n",
    "# pairwise(iterable)\n",
    "# iterable - iterable object\n",
    "# The pairwise() function is an infinite iterator,\n",
    "# so it must be combined with another function that terminates the iteration,\n",
    "# otherwise it goes into an infinite loop.\n",
    "\n",
    "# pairwise() 实现\n",
    "def pairwise(iterable):\n",
    "    a, b = tee(iterable)\n",
    "    next(b, None)\n",
    "    return zip(a, b)\n",
    "\n",
    "x=pairwise([1, 2, 3, 4, 5])\n",
    "for i in x:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# product demo\n",
    "# The product() function returns the cartesian product of input iterables.\n",
    "# The syntax of product() is:\n",
    "# product(*iterables, repeat=1)\n",
    "# iterables - iterables to compute the product of\n",
    "# repeat (optional) - integer specifying how many times the input iterables are to be repeated\n",
    "\n",
    "from itertools import product\n",
    "\n",
    "for i in product([1, 2], [3, 4]):\n",
    "    print(i)  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# permutations demo\n",
    "# The permutations() function returns successive r length permutations of elements in the iterable.\n",
    "# The syntax of permutations() is:\n",
    "# permutations(iterable, r=None)\n",
    "# iterable - iterable object\n",
    "# r (optional) - length of the permutations to be returned\n",
    "# If r is not specified or is None, then r defaults to the length of the iterable,\n",
    "# and all possible full length permutations are generated.\n",
    "# The permutations() function is an infinite iterator,\n",
    "\n",
    "from itertools import permutations\n",
    "\n",
    "for i in permutations([1, 2, 3]):\n",
    "    print(i)\n",
    "\n",
    "for i in permutations([1, 2, 3], 2):\n",
    "    print(i)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# combinations demo\n",
    "# The combinations() function returns successive r length combinations of elements in the iterable.\n",
    "# The syntax of combinations() is:\n",
    "# combinations(iterable, r)\n",
    "# iterable - iterable object\n",
    "# r - length of the combinations to be returned\n",
    "\n",
    "from itertools import combinations\n",
    "\n",
    "for i in combinations([1, 2, 3, 4], 2):\n",
    "    print(i)\n",
    "\n",
    "# combinations_with_replacement demo\n",
    "# The combinations_with_replacement() function returns successive r length combinations of elements in the iterable allowing individual elements to have successive repeats.\n",
    "# The syntax of combinations_with_replacement() is:\n",
    "# combinations_with_replacement(iterable, r)\n",
    "# iterable - iterable object\n",
    "# r - length of the combinations to be returned\n",
    "\n",
    "from itertools import combinations_with_replacement\n",
    "\n",
    "for i in combinations_with_replacement([1, 2, 3], 2):\n",
    "    print(i)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# @lru_cache demo\n",
    "# @lru_cache(maxsize=128, typed=False)\n",
    "# maxsize: the number of calls to cache\n",
    "# typed: if True, arguments of different types will be cached separately\n",
    "#        if False, arguments of different types will be considered the same\n",
    "#        (e.g. 1 and 1.0 will be considered the same)\n",
    "#\n",
    "import sys  # 导入sys模块\n",
    "from functools import lru_cache\n",
    "\n",
    "@lru_cache(maxsize=128)\n",
    "def fib(n):\n",
    "    if n < 2:\n",
    "        return n\n",
    "    return fib(n-1) + fib(n-2)\n",
    "\n",
    "\n",
    "sys.setrecursionlimit((1<<31)-1)  \n",
    "print(fib(10000))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# @total_ordering demo\n",
    "# @total_ordering is a class decorator that fills in missing ordering methods\n",
    "# when possible. It is equivalent to the following code:\n",
    "\n",
    "class MyObject:\n",
    "    def __eq__(self, other):\n",
    "        return self.__dict__ == other.__dict__\n",
    "\n",
    "    def __lt__(self, other):\n",
    "        return self.__dict__ < other.__dict__\n",
    "\n",
    "    def __le__(self, other):\n",
    "        return self.__dict__ <= other.__dict__\n",
    "\n",
    "    def __gt__(self, other):\n",
    "        return self.__dict__ > other.__dict__\n",
    "\n",
    "    def __ge__(self, other):\n",
    "        return self.__dict__ >= other.__dict__\n",
    "    \n",
    "# @total_ordering is equivalent to the following code:\n",
    "from functools import total_ordering\n",
    "\n",
    "@total_ordering\n",
    "class MyObject:\n",
    "    def __eq__(self, other):\n",
    "        return self.__dict__ == other.__dict__\n",
    "\n",
    "    def __lt__(self, other):\n",
    "        return self.__dict__ < other.__dict__\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 多线程\n",
    "import threading\n",
    "import time\n",
    "\n",
    "def worker():\n",
    "    print(threading.current_thread().getName(), 'Starting')\n",
    "    time.sleep(2)\n",
    "    print(threading.current_thread().getName(), 'Exiting')\n",
    "\n",
    "\n",
    "def my_service():\n",
    "    print(threading.current_thread().getName(), 'Starting')\n",
    "    time.sleep(3)\n",
    "    print(threading.current_thread().getName(), 'Exiting')\n",
    "\n",
    "\n",
    "t = threading.Thread(name='my_service', target=my_service)\n",
    "w = threading.Thread(name='worker', target=worker)\n",
    "w2 = threading.Thread(target=worker)  # use default name\n",
    "\n",
    "w.start()\n",
    "w2.start()\n",
    "t.start()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 线程池 演示\n",
    "from concurrent.futures import ThreadPoolExecutor\n",
    "import time\n",
    "\n",
    "\n",
    "def return_future(msg):\n",
    "    time.sleep(3)\n",
    "    return msg\n",
    "\n",
    "\n",
    "pool = ThreadPoolExecutor(max_workers=2)\n",
    "\n",
    "future = pool.submit(return_future, ('hello'))\n",
    "\n",
    "print(future.done())\n",
    "time.sleep(3)\n",
    "print(future.done())\n",
    "print(future.result())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 进程池 演示\n",
    "from concurrent.futures import ProcessPoolExecutor\n",
    "import os\n",
    "import time\n",
    "\n",
    "\n",
    "def return_future(msg):\n",
    "    time.sleep(3)\n",
    "    return msg\n",
    "\n",
    "\n",
    "pool = ProcessPoolExecutor(max_workers=2)\n",
    "\n",
    "future = pool.submit(return_future, ('hello'))\n",
    "print(future.done())\n",
    "time.sleep(3)\n",
    "print(future.done())\n",
    "print(future.result())\n",
    "print('PID: {}'.format(os.getpid()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def fact(n:int)->int:\n",
    "    f={\n",
    "        n==0:lambda n:1,\n",
    "        n==1:lambda n:1,\n",
    "        n==2:lambda n:2,\n",
    "        n>2:lambda n:fact(n-1)*n\n",
    "    }[True]\n",
    "    return f(n)\n",
    "\n",
    "fact(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# operator\n",
    "from sys import _getframe \n",
    "import operator\n",
    "\n",
    "print(_getframe().f_lineno, operator.add(1, 2))\n",
    "print(_getframe().f_lineno, operator.mul(3, 4))\n",
    "print(_getframe().f_lineno, operator.contains([1, 2, 3], 3))\n",
    "print(_getframe().f_lineno, operator.contains([1, 2, 3], 4))\n",
    "x = [1, 2, 3]\n",
    "print(_getframe().f_lineno, operator.setitem(x, 1, 4))\n",
    "print(x)\n",
    "print(_getframe().f_lineno, operator.getitem(x, 1))\n",
    "print(x)\n",
    "print(_getframe().f_lineno, operator.delitem(x, 1))\n",
    "print(x)\n",
    "\n",
    "print(_getframe().f_lineno, operator.itemgetter('a')({'a': 1, 'b': 2}))\n",
    "print(_getframe().f_lineno, operator.attrgetter('__len__')('hello'))\n",
    "print(_getframe().f_lineno, operator.methodcaller('upper')('hello'))\n",
    "print(_getframe().f_lineno, operator.neg(1))\n",
    "print(_getframe().f_lineno, operator.pos(1))\n",
    "print(_getframe().f_lineno, operator.abs(-1))\n",
    "print(_getframe().f_lineno, operator.invert(1))\n",
    "print(_getframe().f_lineno, operator.not_(True))\n",
    "\n",
    "print(_getframe().f_lineno, operator.truth(1))\n",
    "print(_getframe().f_lineno, operator.truth(0))\n",
    "print(_getframe().f_lineno, operator.truth(None))\n",
    "print(_getframe().f_lineno, operator.truth(False))\n",
    "print(_getframe().f_lineno, operator.truth(True))\n",
    "print(_getframe().f_lineno, operator.truth(''))\n",
    "print(_getframe().f_lineno, operator.truth('hello'))\n",
    "print(_getframe().f_lineno, operator.truth([]))\n",
    "print(_getframe().f_lineno, operator.truth([1, 2, 3]))\n",
    "print(_getframe().f_lineno, operator.truth({}))\n",
    "print(_getframe().f_lineno, operator.truth({'a': 1, 'b': 2}))\n",
    "print(_getframe().f_lineno, operator.truth(set()))\n",
    "print(_getframe().f_lineno, operator.truth({1, 2, 3}))\n",
    "print(_getframe().f_lineno, operator.truth(()))\n",
    "print(_getframe().f_lineno, operator.truth((1, 2, 3)))\n",
    "\n",
    "print(_getframe().f_lineno, operator.lt(1, 2))\n",
    "print(_getframe().f_lineno, operator.le(1, 2))\n",
    "print(_getframe().f_lineno, operator.eq(1, 2))\n",
    "print(_getframe().f_lineno, operator.ne(1, 2))\n",
    "print(_getframe().f_lineno, operator.ge(1, 2))\n",
    "print(_getframe().f_lineno, operator.gt(1, 2))\n",
    "print(_getframe().f_lineno, operator.is_(1, 2))\n",
    "print(_getframe().f_lineno, operator.is_not(1, 2))\n",
    "print(_getframe().f_lineno, operator.is_(1, 1))\n",
    "print(_getframe().f_lineno, operator.is_not(1, 1))\n",
    "print(_getframe().f_lineno, operator.is_(1, 1.0))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.3"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
